<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_users
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('behavior.modal');
JHtml::_('formbehavior.chosen', 'select');
		$db	  = &JFactory::getDBO();
		$user    = & JFactory::getUser();
	    $uid  	 = $user->get('id');
		$query   = $db->getQuery(true);
		$query_r = $db->getQuery(true);
		//count row data
		$sonews  = 4;
		$query_r->select('*');
		$query_r->from('#__gallery');
		$query_r->where('user_id='.$uid);
		$db->setQuery($query_r);
		$db->query();
		$num_rows = $db->getNumRows();
		$total = ceil($num_rows/2);
		// Select all records from the user profile table where key begins with "custom.".
		// Order it by the ordering field.
		if(isset($_GET["p"])){$p = intval($_GET["p"]) ;
		}else{$p =1;}
		$x = ($p-1) * $sonews;
		$query->select('*');
		$query->from('#__gallery');
		$query->where('user_id='.$uid);
		// Reset the query using our newly populated query object.
		$db->setQuery($query,$x,$sonews);
		$results = $db->loadObjectList();
?>
<script language ="javascript" type = "text/javascript" >
    function submitDetailsForm()
    {
       jQuery("#adminForm").submit();
    }
	jQuery(function(){
		// add multiple select / deselect functionality
		jQuery("#selectall").click(function () {
			  jQuery('.case').attr('checked', this.checked);
		});
	 
		// if all checkbox are selected, check the selectall checkbox
		// and viceversa
		jQuery(".case").click(function(){
	 
			if(jQuery(".case").length == jQuery(".case:checked").length) {
				jQuery("#selectall").attr("checked", "checked");
			} else {
				jQuery("#selectall").removeAttr("checked");
			}
	 
		});
	});
</script>	
<div class="custom-title">
    <a href="<?php echo JRoute::_('index.php?option=com_profiles&view=gallery');?>">Add Images</a> -
    <a href="#" onClick='submitDetailsForm()'>Delete All</a>
</div>
<form action="<?php echo JRoute::_('index.php?option=com_profiles&task=delAllGallery');?>" method="post" name="adminForm" id="adminForm">
	<table class="table table-striped">
		<thead>
			<tr>
				<th width="1%" class="nowrap center">
					<input type="checkbox" id="selectall" class="check" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>"  />
				</th>
				<th width="25%" class="center">
					Name
				</th>
				<th width="35%" class="nowrap center">
					Images
				</th>
				<th width="15%" class="nowrap center">
					Status
				</th>
				<th width="15%" class="nowrap center">
					Modify
				</th>
				<th width="10%" class="nowrap center">
					Function
				</th>
				
			</tr>
            <?php foreach($results as $row){?>
                <tr>
                  <td class="center"><input class="case" type="checkbox" name="chk[]" value="<?php echo $row->id;?>" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" /></td>
                  <td class="center"><?php echo $row->name;?>&nbsp;</td>
                  <td class="center">
				  	<?php $image =  $row->images;?>&nbsp;
                    <?php if($image!=""){
							$images = explode("/", $image); 
							//print_r($images);
					?>
						<span><img src="../images/background/<?php echo $uid;?>/gallery/<?php echo $images[2];?>" width="100" height="50" /></span>
					<?php } ?>
                  </td>
                  <td class="center"><a href="<?php echo JRoute::_('index.php?option=com_profiles&task=updateStatusGal&id='.$row->id);?>" title="Edit"><?php echo $row->status;?></a>&nbsp;</td>
                  <td class="center"><?php echo $row->modify;?>&nbsp;</td>
                  <td class="center">
                 	 <a href="<?php echo JRoute::_('index.php?option=com_profiles&view=gallery&id='.$row->id);?>" title="Edit">Edit</a> - 
                     <a href="<?php echo JRoute::_('index.php?option=com_profiles&task=delGallery&id='.$row->id);?>" title="Delete">Delete</a>
                  </th>
              	</tr>
            <?php } ?>
		</thead>
		<tfoot>
			<tr>
				<td colspan="15">
					<?php
						for ($i = 1;$i<$total;$i++){
							if($i==$p){ echo "<font color='red'> $i  </font>";
							}else{
								echo "<a  href='index.php?option=com_profiles&view=galleries&p=$i'>$i  </a>";}
						}
                    ?>
				</td>
			</tr>
		</tfoot>
		<tbody>
        	
		</tbody>
	</table>
</form>